﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
//使用指针数组模拟实现二维数组
int main(void)
{
	int arr1[] = { 1,2,3,4,5 };
	int arr2[] = { 2,3,4,5,6 };
	int arr3[] = { 3,4,5,6,7 };

	int* arr[3] = { arr1,arr2,arr3 };
	int i = 0;
	int j = 0;
	for (i = 0; i < 3; i++)
	{
		for (j = 0; j < 5; j++)
		{
			printf("%d", arr[i][j]);
		}
		printf("\n");
	}
	return 0;
}



#if 0
int main(void)
{
	int a = 0;
	int* p = &a;
	int** pp = &p;
	printf("   a = %d\n", a);
	printf("   p = %p\n", p);
	printf("  &a = %p\n", &a);
	printf(" *pp = %p\n",*pp);
	printf("**pp = %d\n", **pp);
	return 0;
} 

int count = 0;
void bubble_sort(int arr[], int sz)
{
	int i = 0;
	for (i = 0; i < sz - 1; i++)
	{
		//一趟冒泡排序
		int flag = 1;//假设是有序的
		int j = 0;
		for (j = 0; j < sz - 1 - i; j++)
		{
			count++;
			if (arr[j] > arr[j + 1])
			{
				int tmp = arr[j];
				arr[j] = arr[j + 1];
				arr[j + 1] = tmp;
				flag = 0;//不是有序的
			}
		}
		if (flag == 1)
		{
			break;
		}
	}
}

void print(int arr[], int sz)
{
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%d ", arr[i]);
	}
	printf("\n");
}

int main(void)
{
	int arr[] = { 0,1,2,3,4,5,6,7,8,9 };
	//排序为升序
	int sz = sizeof(arr) / sizeof(arr[0]);
	bubble_sort(arr,sz);
	print(arr, sz);
	printf("冒泡排序的次数为 %d\n", count);
}
void test1(int arr[])//参数写成数组形式，本质上还是指针
{
	printf("%d\n", sizeof(arr));
}
void test2(int* arr)//参数写成指针形式
{
 printf("%d\n", sizeof(arr));//计算⼀个指针变量的⼤⼩
}
int main()
{
	int arr[10] = { 1,2,3,4,5,6,7,8,9,10 };
	test1(arr);
	test2(arr);
	return 0;
}

void test(int arr[])
{
	int sz2 = sizeof(arr) / sizeof(arr[0]);
	printf("sz2 = %d\n", sz2);
}
int main()
{
	int arr[10] = { 1,2,3,4,5,6,7,8,9,10 };
	int sz1 = sizeof(arr) / sizeof(arr[0]);
	printf("sz1 = %d\n", sz1);
	test(arr);
	return 0;
}

int main()
{
	int arr[10] = { 0 };
	int i = 0;
	int sz = sizeof(arr) / sizeof(arr[0]);
	int* p = arr;
	for (i = 0; i < sz; i++)
	{
		scanf("%d", p + i);
		//scanf("%d", arr+i);//也可以这样写
	}
	for (i = 0; i < sz; i++)
	{
		printf("%d ", p[i]);
	}
	return 0;
}

int main()
{
	int arr[10] = { 0 };
	int i = 0;
	int sz = sizeof(arr) / sizeof(arr[0]);
	int* p = arr;
	for (i = 0; i < sz; i++)
	{
		scanf("%d", p + i);
		//scanf("%d", arr+i);//也可以这样写

	}
	for (i = 0; i < sz; i++)
	{
		printf("%d ", *(p + i));
	}
	return 0;
}

int main()
{
	int arr[10] = { 1,2,3,4,5,6,7,8,9,10 };
	printf("&arr[0]   = %p\n", &arr[0]);
	printf("&arr[0]+1 = %p\n", &arr[0] + 1);
	printf("arr       = % p\n", arr);
	printf("arr+1     = % p\n", arr + 1);
	printf("&arr      = % p\n", &arr);
	printf("&arr+1    = % p\n", &arr + 1);
	return 0;
}

int main()
{
	int arr[10] = { 1,2,3,4,5,6,7,8,9,10 };
	printf("&arr[0] = %p\n", &arr[0]);
	printf("arr     = % p\n", arr);
	printf("&arr    = % p\n", &arr);
	return 0;
}

int main(void)
{
	int arr[] = { 1,2,3,4,5,6,7,8,9,10 };
	printf("arr	= %p\n", arr);
	printf("&arr[0] = %p\n", &arr[0]);
	printf("sizeof(arr) = %d\n", sizeof(arr));
	return 0;
}
#endif
